<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // // 声明一个数组
        // const xiyouji = ['唐僧','孙悟空','猪八戒','沙僧'];
        // // 使用for...of 遍历数组
        // for (let v in xiyouji) {
        //     console.log(v);
        // }
        // console.log(xiyouji);

        // let iterator = xiyouji[Symbol.iterator]();
        // console.log(iterator);
        // // 调用对象的next方法
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());


        // 自定义遍历数据
        const banji = {
            name: "终极一班",
            stus: [
                'aa',
                'bb',
                'cc',
                'dd'
            ],
            [Symbol.iterator]() {
                let index = 0;
                let _this = this;
                return {
                    next: () => {
                        if (index < this.stus.length) {
                            const result = { value: _this.stus[index], done: false };
                            //下标自增
                            index++;
                            //返回结果
                            return result;
                        } else {
                            return { value: underfined, done: true };
                        }
                    }
                }
            }
        }
        for (let v of banji) {
            console.log(v);  // aa bb cc dd
        }

    </script>
</body>

</html>